<?php 	

class BrandController extends AuthController{

   private $model;

  public function __init(){
       
     // 为了不覆盖父类authcontroller里面的init方法
    	parent::__init();
    	$this->model=K('Brand');
 }

// 显示品牌列表
 public function index(){
  $total= $this->model->count();
  $pageObj=new Page($total,10,2);
  $page=$pageObj->show();
$this->assign('page',$page);
// 算出limit的位置
//算出要limit的位置
    $limit = $pageObj->limit();
    //每次点击分页截取不同的数据
    $data = $this->model->limit($limit)->all();
    $this->assign('data',$data);
  
    $this->display();


 }

// 添加品牌
 public function add(){
 	if(IS_POST){

  if(!$this->model->addData()){
  	$this->error($this->model->error);
  }
    $this->success('添加成功',U('index'));

 	}
    $this->display();
 }

// 修改品牌
 public function edit(){
    if(IS_POST){
     $brand_id=Q('post.brand_id',0,'intval');
       if(!$this->model->edit($brand_id)){
        $this->error($this->model->error);
       }
       $this->success('修改成功',U('index'));

    }
    // 获取旧数据
    $brand_id=Q('get.brand_id',0,'intval');
   $olddata=$this->model->where("brand_id={$brand_id}")->find();
   $this->assign('olddata',$olddata);

    $this->display();

 }


// 删除

 public function del(){
 $brand_id=Q('get.brand_id',0,'intval');
 $this->model->where("brand_id={$brand_id}")->delete();
 $this->success('删除成功');

 }













}




















 ?>